USE COUNT of vba in vb6

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

USE COUNT of vba in vb6

Post by sal21 »

Code: Select all

....
Public EXCAPP As Object, EXDOC As Object, WS As Object
...

Set EXCAPP = CreateObject("Excel.Application")
    Set EXDOC = EXCAPP.Workbooks.Open("C:\SERVIZIO\EXPORT\LISTINO_ROCCA.xlsm")
    Set WS = EXDOC.Worksheets("FOGLIO1")
    EXCAPP.Visible = False   
    
...
How to return the value of count in ULTIMA var, with the vba excel function:

VBA
ULTIMA = WS.Range("A" & WS.Rows.Count).End(xlUp).Row + 1
VBA

User avatar
HansV
Administrator
Posts: 78380
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: USE COUNT of vba in vb6

Post by HansV »

You only need to change xlUp to -4162:

Code: Select all

    ULTIMA = WS.Range("A" & WS.Rows.Count).End(-4162).Row + 1
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: USE COUNT of vba in vb6

Post by sal21 »

HansV wrote:
09 Sep 2020, 18:22
You only need to change xlUp to -4162:

Code: Select all

    ULTIMA = WS.Range("A" & WS.Rows.Count).End(-4162).Row + 1
WORK!

Also here have error...
'DELETE ND
WS.Columns("J:J").Select
Selection.Replace What:="#N/D", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'DELETE ND

in xlPart and xlByRows

User avatar
HansV
Administrator
Posts: 78380
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: USE COUNT of vba in vb6

Post by HansV »

To solve this:

- Start Excel.
- Press Alt+F11 to activate the Visual Basic Editor.
- Press F2 to activate the Object Browser.
- Type xlPart in the search box and press Enter.
- You'll see Const xlPart = 2 lower down.
- So you should replace xlPart with 2 in your code.

- Do the same to find the value of xlByRows.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: USE COUNT of vba in vb6

Post by sal21 »

HansV wrote:
09 Sep 2020, 19:35
To solve this:

- Start Excel.
- Press Alt+F11 to activate the Visual Basic Editor.
- Press F2 to activate the Object Browser.
- Type xlPart in the search box and press Enter.
- You'll see Const xlPart = 2 lower down.
- So you should replace xlPart with 2 in your code.

- Do the same to find the value of xlByRows.
OK.
Selection ERROR VARIABLE NOT DEFINED!!!!!


OTHER WAY ARE WELCOME!

User avatar
HansV
Administrator
Posts: 78380
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: USE COUNT of vba in vb6

Post by HansV »

You don't need Selection. Combine the lines to

WS.Columns("J:J").Replace What:="#N/D", ...
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: USE COUNT of vba in vb6

Post by sal21 »

HansV wrote:
09 Sep 2020, 19:55
You don't need Selection. Combine the lines to

WS.Columns("J:J").Replace What:="#N/D", ...
great!