Finding the next empty cell (Even if a formula exists)

Todd_M

Board Regular
Joined
Feb 24, 2002
Messages
117
Hi-

matchcol = Cells(x, "cb").End(xlToLeft).Column

This code finds the next empty cell to the left of column "CB". But if theres a formula (even though the cell is blank)the code chooses that cell. How can I rearange that code so that it wont reconize a formula in the cell, but just the first cell with actuall text?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
If there is always this cell with a formula at the end then you can just offset over 1:

matchcol = Cells(x, "cb").End(xlToLeft).Columns.Offset(0, -1).Select

or put a loop after it:

matchcol = Cells(x, "cb").End(xlToLeft).Columns.Select
Do While ActiveCell.Formula<> ""
On Error GoTo 1
ActiveCell.Offset(0, -1).Select
Loop
1



_________________
Hope this helps.
Kind regards, Al.
This message was edited by Al Chara on 2002-04-10 13:26
 
Upvote 0
Al- Thanks for responding, All the cells that this code uses contian formulas. The formula pulls text from another part of the sheet. (ex: cell BX3 has a formula that reads =T3) So if cell T3 contains a number then that duplicate number is copied in cell BX3. All cells that the code uses consists of these type formulas. The cells maybe blank, but the code doesnt read it that way. How would you suggest that I could still use:


matchcol = Cells(x, "cb").End(xlToLeft).Column

and find the next empty cell (even though theres a formula in it)
 
Upvote 0
Ok heres the full code:


Private Sub CommandButton6_Click()
Dim lastrow As Long, x As Long
Dim matchday As Integer, matchcol As Integer
Dim myarr(1 To 7)

matchday = WorksheetFunction.Match(Format(Date, "dddd"), Rows("1:1"), 0)

lastrow = Cells(Rows.Count, "bt").End(xlUp).Row
For x = 2 To lastrow
matchcol = Cells(x, "cb").End(xlToLeft).Column

If matchcol <> matchday Then GoTo E
MsgBox Cells(x, 72) & " gets paid today."
E:
Next x
End Sub


What Im try to acomplish is a work schedual for employees. The schedual is actually written in another part of the same sheet. I cant use the code on the original part becouse theres to many varibles and spaces. So what im trying to do is consolidate the important info in another part of the sheet by just having those cells in question using a formula (=T1). The code works well when I manualy enter numbers(Times), but the times have to be posted automatically from the first part of the sheet(using the formulas). Thats why the section of cells that the code reads all contain formulas, even though some cells are blank.
 
Upvote 0
I apologize, I was reading what you wanted to do completely backwards. I think this is closer to a solution. The do loop works, I didn't test the rest.

Code:
Private Sub CommandButton6_Click()
Dim lastrow As Long, x As Long
Dim matchday As Integer, matchcol As Integer
Dim myarr(1 To 7)

matchday = WorksheetFunction.Match(Format(Date, "dddd"), Rows("1:1"), 0)

lastrow = Cells(Rows.Count, "bt").End(xlUp).Row
For x = 2 To lastrow
Cells(x, "cb").Select
Do
On Error GoTo 1
ActiveCell.Offset(0, -1).Select
Loop Until Application.WorksheetFunction.IsNumber(ActiveCell.Value) = True And ActiveCell.Value<> 0
1
If matchcol<> matchday Then GoTo E
MsgBox Cells(x, 72) & " gets paid today."
E:
Next x
End Sub
_________________
Hope this helps.
Kind regards, Al.
This message was edited by Al Chara on 2002-04-10 15:47
This message was edited by Al Chara on 2002-04-10 15:48
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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