VBA Current Region With Value Not Formula

jusho

New Member
Joined
Jun 2, 2014
Messages
39
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I have a sheet that contain data from A1:E10. In A2 to A10 i have a formula =if(B2="","",A1+1). So if there is no data in row 2 so on there will not seen the number in column A. Then i try to copy currentregion using vba to select all cell with data but it always select all A1:E10 its because there is formula in column A. Any way to select only row with value maybe from A1:E5. Thanks.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Use the special cells method:
Code:
Range("A1:E5").SpecialCells(xlCellTypeFormuals, 1).Select
 
Upvote 0
Use the special cells method:
Code:
Range("A1:E5").SpecialCells(xlCellTypeFormuals, 1).Select

Here my case. In column A3 till A10 there a formula =if(b3="","",a2+1). So if there is no data in column B3, the number in A3 wil not show. But actually there is formula inside. The problem when i currentregion it select all A1:E10, i need the current region only select the cell that contain data not formula, so the result it will select A1:E5. So i dont want put static range in vba.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]No[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Try the following NotBlank Function (with a sub to show its usage):

Code:
Sub test()
Dim C00 As Range
Set C00 = NotBlank(Range("A1").CurrentRegion)
Debug.Print C00.Address
End Sub


Function NotBlank(Rng As Range) As Range
Dim C01 as Range
Set NotBlank = Nothing
For Each C01 In Rng
    If C01.Value <> "" Then
        If NotBlank Is Nothing Then
            Set NotBlank = C01
        Else
            Set NotBlank = Application.Union(NotBlank, C01)
        End If
    End If
Next
End Function
 
Upvote 0
See if this helps
Rich (BB code):
Sub GetRange()
  Dim lr As Long
 
  lr = Columns("A").Find(What:="*", After:=Range("A1"), LookIn:=xlValues, SearchDirection:=xlPrevious, SearchFormat:=False).Row
  Range("A1:E" & lr).Select
End Sub
 
Upvote 0
I will try it tommorow at work. Tx for reply.
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,144
Members
452,547
Latest member
Schilling

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