VBA Question/Help

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
814
Office Version
  1. 2010
Platform
  1. Windows
I have the following code and want to change the location of the calculations.

I'm not sure how the cell row column etc. works but here goes:

I current have the calculations in 1 worksheet in cell column A1:A1000 and the calculations that remove the blank cells is in column B1:B1000.
I want to change it in cell range AF1:AF1000 and the calculations in cell range AK1:AK1000

Would I need to change the Cells(i, 1) another value to match cell column AF?

Thanks in advance!!


Code:
Sub DeleteBlankRows()

Dim counter As Integer, i As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
counter = 0

For i = 1 To 1000
    If Cells(i, 1).Value <> "" Then
        Cells(counter + 1, 2).Value = Cells(i, 1).Value
        counter = counter + 1
    End If
Next i

Range("F1").Select
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Alan_P

Well-known Member
Joined
Jul 8, 2014
Messages
596
Hi ststern45,

You can just change to the column text...

Code:
Sub DeleteBlankRows()

Dim counter As Integer, i As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
counter = 0

For i = 1 To 1000
    If Cells(i, [COLOR="#FF0000"]"AF"[/COLOR]).Value <> "" Then
        Cells(counter + 1, [COLOR="#FF0000"]"AK"[/COLOR]).Value = Cells(i, [COLOR="#FF0000"]"AF"[/COLOR]).Value
        counter = counter + 1
    End If
Next i

Range("F1").Select
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub

Hope this helps,
Cheers,
Alan.
 
Last edited:

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
814
Office Version
  1. 2010
Platform
  1. Windows
Thanks Alan it works great!!

Thank you so much!!
 

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
814
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

Just a followup question

Ho do I change the code to range AF20:AF1019 and AK20:AK1019

Thanks in advance!!

Sub DeleteBlankRows()

Dim counter As Integer, i As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
counter = 0

For i = 1 To 1000
If Cells(i, "AF").Value <> "" Then
Cells(counter + 1, "AK").Value = Cells(i, "AF").Value
counter = counter + 1
End If
Next i

Range("F1").Select
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,766
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Do you mean...
Rich (BB code):
For i = 1 To 1000

TO

For i = 20 To 1019
 

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
814
Office Version
  1. 2010
Platform
  1. Windows
Thanks

I also change

counter = 0

counter = 19
 

Watch MrExcel Video

Forum statistics

Threads
1,123,143
Messages
5,599,975
Members
414,354
Latest member
Flaxarn

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