Ignore formula when counting columns

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
147
Hello, everyone,
I was able to figure this macro out almost completly. However, I'm missing a piece which I never dealt with before.

Basically, I have one excel file which I update monthly and I need to get the figures from a colleague's workbook. However, the code below doesn't compute lr2 properly because there are formulas afterwards, although there is no value in it.


Code:
Sub GetCarlaValues()Dim sourcefile As Workbook, Dados As Worksheet, lc As Integer, lc2 As Integer, lr As Integer


lr = KRIs.Cells(Rows.Count, 2).End(xlUp).Row
lc = KRIs.Cells(85, Columns.Count).End(xlToLeft).Column


Set sourcefile = Workbooks.Open("path\workbook1.xlsx")


lr2 = ActiveWorkbook.Worksheets("Dados").Cells(516, Columns.Count).End(xlToLeft).Column


KRIs.Cells(85, lc) = Dados.Cells(516, lc2)
KRIs.Cells(86, lc) = Dados.Cells(510, lc2)
KRIs.Cells(87, lc) = Dados.Cells(515, lc2)
KRIs.Cells(152, lc) = Dados.Cells(594, lc2)
KRIs.Cells(153, lc) = Dados.Cells(587, lc2)
KRIs.Cells(154, lc) = Dados.Cells(590, lc2)
KRIs.Cells(167, lc) = Dados.Cells(554, lc2)
KRIs.Cells(168, lc) = Dados.Cells(557, lc2)
KRIs.Cells(169, lc) = Dados.Cells(552, lc2)


End Sub


JanFebMarchAprilMayJuneJulyAugustSeptOctNovDec
5555555FormulaFormulaFormulaFormulaFormula

<tbody>
</tbody>


I would like the sub to ignore the cells with formulas and return me the number of the column from July, in this case. Is there any way to do this?

For reference, in the sub I posted above, it returns me 62 when it should return 56

Thanks for your help,
ORoxo
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,907
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Maybe...

Code:
lr2 = ActiveWorkbook.Worksheets("Dados").Rows(516).Find("*", _
    SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column

M.
 

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
147
Maybe...

Code:
lr2 = ActiveWorkbook.Worksheets("Dados").Rows(516).Find("*", _
    SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column

M.

That worked, Marcelo!
Thank you

btw I tried to include "UpdateLinks:=3" in the sub after the line to open the workbook to get the alarms off when opening the worksheet but that didn't work. Do you have any idea why?
 

Forum statistics

Threads
1,148,108
Messages
5,744,878
Members
423,907
Latest member
zerocool88

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
Top