PDA

View Full Version : Syntax issue



John R
09-13-2023, 11:09 AM
I am rather new to VB and I am trying unsuccessfully to combine two formulas into one.

Rows(5).Select ------ This formula lets me select row 5 of the current worksheet

‘data’!G11 ------ Cell G11 in the data worksheet is the one I want to substitute for row 5

Rows(‘data’!G11). ------ Select this is sort of what I am after but I cant seem to find the correct syntax to incorporate the cell into the formula. I am using it in a useform.

Any help would be appreciated.

June7
09-13-2023, 03:49 PM
Don't use smart apostrophes or quotes (aka tilted apostrophe/quote) in code.

You want value from cell G11?

It usually is not necessary to actually "Select" anything when manipulating Excel.

Is "data" the sheet name?

Rows(Worksheets("data").Range("G11")).Select

What are you trying to accomplish?

Aussiebear
09-13-2023, 05:04 PM
Welcome to VBAX John R. As June7 has suggested the format needs to be
Rows(Worksheets("data").Range("G11")

June7
09-13-2023, 06:04 PM
Aussie, missing closing parenthesis :rotlaugh:

Aussiebear
09-14-2023, 01:05 AM
A swing and a miss......about my standard

John R
09-14-2023, 11:47 AM
I was trying to select a specific row to copy it. I worked around the issue by putting using a variable and putting that into the script instead. Your format looks much cleaner, I am going to convert it over to your method. Thanks!!!

June7
09-14-2023, 12:10 PM
Again, it is not necessary to actually "Select" to copy or get values.

Review https://stackoverflow.com/questions/45231135/copy-single-row-to-another-sheet-vba-excel


Another method of copying data to another sheet:

xlApp.Worksheets("Sheet1").Range("A1:AM900").Value = Worksheets("Results").Range("A2:AM900").Value