Help with Object Required error

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I'm at a complete loss here. I'm trying to add a value to a range of cells...something I've done countless times. This time, I'm getting an Object required error. The only nuance I can think of is the range, but the row numbers are being identified correctly.

VBA Code:
Sub ImportReqResults()

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Dim m As Workbook, s As Workbook
Dim mD As Worksheet, sD As Worksheet
Dim mDLR As Long, sDLR As Long, mDNLR As Long

Set m = ThisWorkbook
Set mD = m.Sheets("Data")

mDLR = mD.Range("C" & Rows.Count).End(xlUp).Row
mDNR = mD.Range("C" & Rows.Count).End(xlUp).Row + 1

'I perform various updates here

mDNLR = mD.Range("C" & Rows.Count).End(xlUp).Row


'Adds the Data Source name in the Data Source column of this workbook.
With mD.Range("A" & mDNR) & ":" & mD.Range("A" & mDNLR)
    .Value = "Req Results" 'Error appears here.
End With

'Adds Today's date in the Source Ingested column of this workbook.
With mD.Range("B" & mDNR) & ":" & mD.Range("B" & mDNLR)
    .Value = "=Today()"
    .NumberFormat = "MM/DD/YY"
    .Value = .Value
End With

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You've got the syntax wrong - it should be:

Code:
With mD.Range("A" & mDNR & ":A" & mDNLR)

rather than:

Code:
With mD.Range("A" & mDNR) & ":" & mD.Range("A" & mDNLR)

and the same for the B column range below that.
 
Last edited:
Upvote 0
Solution
You've got the syntax wrong - it should be:

Code:
With mD.Range("A" & mDNR & ":"A" & mDNLR)

rather than:

Code:
With mD.Range("A" & mDNR) & ":" & mD.Range("A" & mDNLR)

and the same for the B column range below that.
Thanks @RoryA . I had to make a small tweak, and wound up with this working snippet.
VBA Code:
With mD.Range("A" & mDNR & ":" & "A" & mDNLR)
 
Upvote 0
Oops - I left an extra quote in. I've amended my previous answer - there is no need for ":" & "A" when you can just use ":A"
 
Upvote 0
That makes sense.
In the future, when marking a post as the solution, please mark the actual post that contains the solution, not your post acknowledging that another post is the solution.
I have updated this thread for you.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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
Back
Top