VBA help with active cell/active row range

cgmojoco

Well-known Member
Joined
Jan 15, 2005
Messages
699
How do I set this up so I can use the range of the row that the user has selected either by cell or by entire row?

rngActiveRow is where I am having trouble?

Code:
sPath = "C:\Test\"                                                              'SET
sName = "CHECKREQUEST.xls"                                                     'SET

Set wbXXX = ActiveWorkbook                                                      'SET
rngActiveRow = Range(Selection.Row)
Set wsMASTER = wbXXX.Sheets("MASTER")                                           'SET
Set wbYYY = Workbooks.Open(sPath & sName)                                       'SET
Set wsYYY = wbYYY.Sheets("CHECKREQUEST")                                        'SET



        wsYYY.Cells(12, "b").Value = wsMASTER.Cells(rngActiveRow, "k").Value 'LandLordName
        wsYYY.Cells(12, "g").Value = wsMASTER.Cells(rngActiveRow, "ai").Value 'Total
        wsYYY.Cells(22, "g").Value = wwsMASTER.Cells(rngActiveRow, "f").Value 'InvoiceDate
        wsYYY.Cells(26, "e").Value = wsMASTER.Cells(rngActiveRow, "e").Value 'Invoice#
        wsYYY.Cells(28, "e").Value = wsMASTER.Cells(rngActiveRow, "f").Value 'Invoice#
        wsYYY.Cells(31, "h").Value = wsMASTER.Cells(rngActiveRow, "d").Value 'Branch#
        wsYYY.Cells(34, "c").Value = Formula = "=UserNameOffice()" 'Username
        wsYYY.Cells(34, "c").Value = Formula = "=UserNameOffice()" 'InvoiceDate
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

cgmojoco

Well-known Member
Joined
Jan 15, 2005
Messages
699
Hmm yes, I tried that earlier, and that is why I was trying that funky stuff above ;)

Run-time error '91'
Object variable or With block variable not set

Happens on that line rngActiveRow= ActiveCell.Row
Code:
Dim wbXXX As Workbook, wbYYY As Workbook
Dim wsMASTER As Worksheet, wsYYY As Worksheet
Dim rngActiveRow As Range
'******************************************************************************
'******************************************************************************
'Setting Variables
'******************************************************************************
'******************************************************************************
          
'sPath = "G:\Accounting\Rents\Rent Rolls\Working\"                              'SET
sPath = "C:\Test\"                                                              'SET
sName = "CHECKREQUEST.xls"                                                     'SET

Set wbXXX = ActiveWorkbook                                                      'SET
rngActiveRow = ActiveCell.Row
Set wsMASTER = wbXXX.Sheets("MASTER")                                           'SET
Set wbYYY = Workbooks.Open(sPath & sName)                                       'SET
Set wsYYY = wbYYY.Sheets("CHECKREQUEST")                                        'SET



        wsYYY.Cells(12, "b").Value = wsMASTER.Cells(rngActiveRow, "k").Value 'LandLordName
        wsYYY.Cells(12, "g").Value = wsMASTER.Cells(rngActiveRow, "ai").Value 'Total
        wsYYY.Cells(22, "g").Value = wwsMASTER.Cells(rngActiveRow, "f").Value 'InvoiceDate
        wsYYY.Cells(26, "e").Value = wsMASTER.Cells(rngActiveRow, "e").Value 'Invoice#
        wsYYY.Cells(28, "e").Value = wsMASTER.Cells(rngActiveRow, "f").Value 'Invoice#
        wsYYY.Cells(31, "h").Value = wsMASTER.Cells(rngActiveRow, "d").Value 'Branch#
        wsYYY.Cells(34, "c").Value = Formula = "=UserNameOffice()" 'Username
        wsYYY.Cells(34, "c").Value = Formula = "=UserNameOffice()" 'InvoiceDate
 
Upvote 0

Forum statistics

Threads
1,190,957
Messages
5,983,835
Members
439,864
Latest member
qazxsw12

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top