need code help or correction

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
Can any one pls help here..
Filter Col AB as a blank values. Select first row after header and give cell name as "False". Then copy this "False" value for rest of the filtered rows.

VBA Code:
LastRow = Range("A2", Range("A" & Rows.Count).End(xlUp)).Count

Range("AB1").Select
ActiveSheet.Range("$A$1:$AM$" & LastRow).AutoFilter Field:=28, Criteria1:="="

Dim r As Long
r = Range("A2:A" & Rows.Count).SpecialCells(xlVisible)(1).Row

Range("AB" & r).Select
ActiveCell.FormulaR1C1 = "FALSE"

'To get last row number after filter the COl AB
Dim FinalRowFiltered As Long, dataRange As Range
Set dataRange = Range("$AB$2:$AB$" & LastRow)
With dataRange.SpecialCells(xlCellTypeVisible)
    FinalRowFiltered = .Areas(.Areas.Count).Row + .Areas(.Areas.Count).Rows.Count
    'MsgBox FinalRowFiltered
End With

Range("AB" & r).Select
Selection.Copy
'instead of below line..
Range("AB3:AB" & FinalRowFiltered).Select
'I need in this way
Range("AB"&r+1 ":" "AB" & FinalRowFiltered).Select

Selection.SpecialCells(xlCellTypeVisible).Select
ActiveSheet.Paste
Application.CutCopyMode = False

Range("AB1").Select
ActiveSheet.Range("$A$1:$AM$" & LastRow).AutoFilter Field:=28, Criteria1:="False"
 
You are declaring "rn" to be a range and trying to use it like a range in your code.
Rich (BB code):
        Dim rn As Range

But you are NOT setting it equal to a range, you are setting it equal to a number (specifically, a row number).
Rich (BB code):
        rn = .Range("A" & .Rows.Count).End(xlUp).Row
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You are declaring "rn" to be a range and trying to use it like a range in your code.
Rich (BB code):
        Dim rn As Range

But you are NOT setting it equal to a range, you are setting it equal to a number (specifically, a row number).
Rich (BB code):
        rn = .Range("A" & .Rows.Count).End(xlUp).Row
Thanks Joe, for explanation, this actually helps... I just did a copy-paste code, and dont have idea to achieve it. Any better idea or method from you guys, pls share then.. 🙂
 
Upvote 0
I have not been following along in this thread, so have no idea what you are ultimately doing (and really am not interested in reading through 40 old posts!).
I just saw your last post, and saw the obvious discrepancy there.

Note that the calculation is getting a row number. Once you have the row number, you can build the range, much like you did earlier in your code here:
VBA Code:
Set dataRange = Range("$AB$2:$AB$" & LastRow)

Note that all ranges must be built using the "Set" command (which i used to set values of all Objects).
For values (like numbers and strings), you do not use the "Set" command.
So anything that you build without the "Set" command cannot be a range.
 
Upvote 0
Hi Alex and Mark, any code help on my post no. #40 please.. I still not able to proceed anything
 
Upvote 0
Hi Alex and Mark, any code help on my post no. #40 please.. I still not able to proceed anything
I'm sorry, I did not get what Joe explained me in post no #43.. I just got that I tried that code of line it got the concept. Thanks Joe for this help..
 
Upvote 0
VBA Code:
Workbooks(WB_PP).Close savechanges:=True Filename:="D:\...\PP.xlsx"
I'm getting Type mismatch error.. any specific reason why?
 
Upvote 0
VBA Code:
If .Rows("2:2") <> "" Then
I'm getting an error here, Type Mismatch.
I'm trying here, whether row 2 has a value.. or not
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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