Select cells with data only via code

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys, I have these 2 working sheets. Except cell D1 on Sheet Gross and cell A1 in Sheet Extract, the sheet is protected and hidden. I select the date in cell A1 Sheet Extract with a formula, to get the month from Sheet Gross I want to work. When I run the code, the cells from A1 to AE1 are selected. I want the code to select only the cells which have date and not blank. I need your expert advice to change the code. The line of code I am using is Range("A1:AE1").Select
I want the code to select A1 till the end where the dates end. Different months have different number of days like 28, 29 , 30 and 31.

Query Remove dates if not of that month.xlsx
ABABACADAE
101-02-202202-02-202228-02-2022   
2
3
4
Extract
Cell Formulas
RangeFormula
A1A1=Gross!A14
B1,AB1B1=A1+1
AC1:AE1AC1=IF(AB1="","",IF(MONTH(AB1+1)=MONTH($A1),AB1+1,""))


Query Remove dates if not of that month.xlsx
ABCD
12021-22
2
3Month
4Apr-21
5May-21
6Jun-21
7Jul-21
8Aug-21
9Sep-21
10Oct-21
11Nov-21
12Dec-21
13Jan-22
14Feb-22
15Mar-22
Gross
Cell Formulas
RangeFormula
A4:A15A4=IF(DATE(LEFT($D$1,4),ROW(A4),1)<=DATE(LEFT($D$1,2)&RIGHT($D$1,2),ROW($A$3),1),DATE(LEFT($D$1,4),ROW(A4),1),"")


Due to the formula in cells AC1:AE1 it is selecting the whole row. I want it to select the cells which contain value and not blank. This is the full code...
Option Explicit

Sub RandomFigures()

Sheets("Extract").Select
'change range below here for days as per month
Range("A2:AE619").Select
Selection.FormulaR1C1 = "=RANDBETWEEN(10,90*10)*10"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'change range below here for days as per month
Range("A1:AE1").Select
Sheets("Gross").Select
Range("AJ5 ").Select


End Sub
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello guys, I have these 2 working sheets. Except cell D1 on Sheet Gross and cell A1 in Sheet Extract, the sheet is protected and hidden. I select the date in cell A1 Sheet Extract with a formula, to get the month from Sheet Gross I want to work. When I run the code, the cells from A1 to AE1 are selected. I want the code to select only the cells which have date and not blank. I need your expert advice to change the code. The line of code I am using is Range("A1:AE1").Select
I want the code to select A1 till the end where the dates end. Different months have different number of days like 28, 29 , 30 and 31.

Query Remove dates if not of that month.xlsx
ABABACADAE
101-02-202202-02-202228-02-2022   
2
3
4
Extract
Cell Formulas
RangeFormula
A1A1=Gross!A14
B1,AB1B1=A1+1
AC1:AE1AC1=IF(AB1="","",IF(MONTH(AB1+1)=MONTH($A1),AB1+1,""))


Query Remove dates if not of that month.xlsx
ABCD
12021-22
2
3Month
4Apr-21
5May-21
6Jun-21
7Jul-21
8Aug-21
9Sep-21
10Oct-21
11Nov-21
12Dec-21
13Jan-22
14Feb-22
15Mar-22
Gross
Cell Formulas
RangeFormula
A4:A15A4=IF(DATE(LEFT($D$1,4),ROW(A4),1)<=DATE(LEFT($D$1,2)&RIGHT($D$1,2),ROW($A$3),1),DATE(LEFT($D$1,4),ROW(A4),1),"")


Due to the formula in cells AC1:AE1 it is selecting the whole row. I want it to select the cells which contain value and not blank. This is the full code...
Option Explicit

Sub RandomFigures()

Sheets("Extract").Select
'change range below here for days as per month
Range("A2:AE619").Select
Selection.FormulaR1C1 = "=RANDBETWEEN(10,90*10)*10"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'change range below here for days as per month
Range("A1:AE1").Select
Sheets("Gross").Select
Range("AJ5 ").Select


End Sub
## Solved
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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