Setting A Range In Conjunction w/ Variables

evxret

New Member
Joined
Apr 8, 2022
Messages
38
Office Version
  1. 365
Platform
  1. Windows
Hello, I am struggling to finish off this macro that adds an "Open Status" Next to all NEW lines of data. Because the column has a bunch of blank values, I cant use End(xlUp) because it won't line up with new data added.
Essentially, all I am attempting to figure out is where I am going wrong when including variables In my range selection. Here is my code;
VBA Code:
Sub movenewposdb()
'
' movenewposdb Macro
'

'   ``Filter New Orders
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("$A$1:$K$1000").AutoFilter Field:=11, Criteria1:="#N/A"
  
    ''Set Variables
    Dim LR As Long
    Dim DBLR As Long
    Dim ws As Worksheet
    Dim ALLws As Worksheet
    Dim Rng As Range
  
    Set ws = Worksheets("Test Ship Report")
    Set ALLws = Worksheets("ALL Orders Database")
  
    DBLR = Sheets("ALL Orders Database").Cells(Rows.Count, 3).End(xlUp).Offset(1).Row
    LR = ws.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
    Set Rng = ALLws.Cells(DBLR, 2).Resize(LR)
  
Rng.Select
    Selection.Value = "Open"

End Sub
The Rng.Select Line is where its failing. I pulled that part of the code directly from code I found here in this forum that was reported as working, So I can seem to figure out where I went wrong.
"Select Method of Range Class" is the error VBA is giving me.

1656094222330.png

If this is of any help, heres a very dumbed down version of what im attemping to do.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi,
try removing the Select statement in your code

change this

VBA Code:
Rng.Select
    Selection.Value = "Open"

to this

VBA Code:
Rng.Value = "Open"

and see if resolves

Dave
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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