VBA to fill values to next column

nburaq

Board Regular
Joined
Apr 2, 2021
Messages
222
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi Gents,
I need VBA code (I don't know how to do it with formula) to convert the values screenshot 1 to screenshot 2. I am dealing generally this kind of data sheets sometimes a combination of letters and numbers so if it could be a general solution It can be so nice! Thanks for help and comments!
1_.png
2_.png
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
with formula I have a trick ;
Excel Formula:
IF(ISBKANK(A2);"";IF(A2>100;"";A2))
However then I have to write similar IF formula to distribute the values to another columns and then I have to delete original column to convert situation1 to 2
 
Upvote 0
How about
VBA Code:
Sub nburaq()
   Dim Rng As Range
   Dim r As Long
   
   For Each Rng In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      For r = 2 To Rng.Count Step 2
         Rng(r).Offset(-1, 1).Value = Rng(r).Value
         Rng(r).ClearContents
      Next r
   Next Rng
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub nburaq()
   Dim Rng As Range
   Dim r As Long
  
   For Each Rng In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      For r = 2 To Rng.Count Step 2
         Rng(r).Offset(-1, 1).Value = Rng(r).Value
         Rng(r).ClearContents
      Next r
   Next Rng
End Sub
it is called magic :) !!! Thanks a lot! I assume Offset (-1,1) writes the values a row above and a next column, and step 2 is since they cell values are next to each other right? Nice... Any link where can I learn VBA programming for Excel only?
 
Upvote 0
You're welcome & thanks for the feedback.
There are plenty of sites on the net that deal with Excel VBA.
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,604
Members
449,174
Latest member
ExcelfromGermany

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