ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Static variable (https://www.excelbanter.com/excel-programming/332792-re-static-variable.html)

cottage6

Static variable
 
Tom, thanks for the reply. Actually I found what I needed to deal with a
little farther down in the code. I need another counter to compensate for
the new rows. Thanks again!

"Tom Ogilvy" wrote:

Static means that copycntr retains the value after the macro terminates.

You can perhaps dispense with it using something like

Dim rng as Range
with Worksheets("Destination")
set rng = .cells(rows,count,"A").End(xlup)
if rng.row < 7 then
set rng.row = .Cells(7,1)
else
if not isempty(rng) then
set rng = rng.offset(2,0)
end if
end if
End With

SourceData.copy Destination:=rng

--
regards,
Tom Ogilvy


"cottage6" wrote in message
...
I'm not sure if this is enough of the code to explain my problem, but here
goes. This code was created by somebody else and I need to figure out

what
the static variable is doing. The macro allows users to retrieve multiple
files into 1 spreadsheet, and the data from each file appends under the

next.
The problem is the user sometimes adds a new row before retrieving the

next
file, and the new data is pasted over the top of the added row. I seems to

me
that I need to reset the copycntr variable if a new row is added, but I'm
totally confused. For example, the second file gets pasted into row 12
instead of row 7. Where in the code does copycntr know to change to row

12?
I hope I haven't made too much of a fool of myself; thanks for any help I

can
get!

Static copycntr
If Sheets("Store Data").Range("C7").Value = 0 Or Sheets("Store
Data").Range("C7").Value = "" _
Then copycntr = ""
If copycntr = "" Then
'If this is the first file being retrieved, the store number will be blank
'so set copycntr to 7, combine with "F", and copy the file data to cell

F7.
'First data row in Store Data sheet is Row 7.

copycntr = 7

End If






All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com