J
John Keith
I have added a logging feature to my excel project that keys off a button
press. When ever the button is clicked I want the data residing in a group
of cells to be copied (logged) to the next empty row in a "log" worksheet.
I have added some code that works, but it seems to be very inefficient.
What is a better(faster, more efficient) way to accomplish this...
(slow code)
' Button is set in a case stmt by reading the name of the button pressed (i
have
' 35 or so buttons on the 1st worksheet next to the BB## cells
' BH94 is always logged, BB95:BK95 is the row to log where Button is the
' row indicator (94+button)
v1 = Worksheets("Source").Range("BH94").Value
v2 = Worksheets("Source").Range("BB94").Offset(Button, 1).Value
v3 = Worksheets("Source").Range("BB94").Offset(Button, 2).Value
v4 = Worksheets("Source").Range("BB94").Offset(Button, 5).Value
v5 = Worksheets("Source").Range("BB94").Offset(Button, 4).Value
v6 = Worksheets("Source").Range("BB94").Offset(Button, 9).Value
v7 = Worksheets("Source").Range("BB94").Offset(Button, 8).Value
' find empty row in "log"; row(0) is the heading line in actual row1
' so intCLRow = 1 points to the 2nd row on the "log" sheet
Set x = Worksheets("Log").Range("A1").Cells
intCLRow = 0
Do While x > ""
intCLRow = intCLRow + 1
x = Worksheets("Log").Range("A1").Offset(intCLRow, 0).Value
Loop
'
' Record results into Log; intCLRow is set to the first empty row to fill
Worksheets("Log").Range("A1").Offset(intCLRow, 0).Value = v1
Worksheets("Log").Range("A1").Offset(intCLRow, 1).Value = v2
Worksheets("Log").Range("A1").Offset(intCLRow, 2).Value = v3
Worksheets("Log").Range("A1").Offset(intCLRow, 3).Value = v4
Worksheets("Log").Range("A1").Offset(intCLRow, 4).Value = v5
Worksheets("Log").Range("A1").Offset(intCLRow, 5).Value = v6
Worksheets("Log").Range("A1").Offset(intCLRow, 6).Value = v7
press. When ever the button is clicked I want the data residing in a group
of cells to be copied (logged) to the next empty row in a "log" worksheet.
I have added some code that works, but it seems to be very inefficient.
What is a better(faster, more efficient) way to accomplish this...
(slow code)
' Button is set in a case stmt by reading the name of the button pressed (i
have
' 35 or so buttons on the 1st worksheet next to the BB## cells
' BH94 is always logged, BB95:BK95 is the row to log where Button is the
' row indicator (94+button)
v1 = Worksheets("Source").Range("BH94").Value
v2 = Worksheets("Source").Range("BB94").Offset(Button, 1).Value
v3 = Worksheets("Source").Range("BB94").Offset(Button, 2).Value
v4 = Worksheets("Source").Range("BB94").Offset(Button, 5).Value
v5 = Worksheets("Source").Range("BB94").Offset(Button, 4).Value
v6 = Worksheets("Source").Range("BB94").Offset(Button, 9).Value
v7 = Worksheets("Source").Range("BB94").Offset(Button, 8).Value
' find empty row in "log"; row(0) is the heading line in actual row1
' so intCLRow = 1 points to the 2nd row on the "log" sheet
Set x = Worksheets("Log").Range("A1").Cells
intCLRow = 0
Do While x > ""
intCLRow = intCLRow + 1
x = Worksheets("Log").Range("A1").Offset(intCLRow, 0).Value
Loop
'
' Record results into Log; intCLRow is set to the first empty row to fill
Worksheets("Log").Range("A1").Offset(intCLRow, 0).Value = v1
Worksheets("Log").Range("A1").Offset(intCLRow, 1).Value = v2
Worksheets("Log").Range("A1").Offset(intCLRow, 2).Value = v3
Worksheets("Log").Range("A1").Offset(intCLRow, 3).Value = v4
Worksheets("Log").Range("A1").Offset(intCLRow, 4).Value = v5
Worksheets("Log").Range("A1").Offset(intCLRow, 5).Value = v6
Worksheets("Log").Range("A1").Offset(intCLRow, 6).Value = v7