VBA: Search related HEADING and arrange into next table

BerndH

New Member
Joined
Nov 24, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I'm new to the forum and also new to learning about VBA. I already spent more than 5,000 hours with Excel, but not more than 40 hours with VBA.

I am trying to solve a problem with VBA and fail to solve the task.

I would like to arrange the associated title (A, B, C) from the cell range B4:D11 in the new table F4:Q11.

Dilemma-eng.png



My approach was as follows:

1. Convert month as a number (e.g. March is the number 3)

2. then I start in the same row (row 4) in column E and move the number of fields to the right (e.g. start at E4 + 3 fields to the right, then I am at H4).

3. The heading "A" should be pasted in there H4. Unfortunately, I don't know how to get to the eading "A".



Unfortunately, I also don't know how to create a loop from it that goes through all 3 fields (e.g. B4, B5, B6) in each line and then does the same in the line below.

Could someone please help me with the implementation please :)

Thank you in advance!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi BerndH. This seems to work. HTH. Dave
Code:
Sub test()
Dim LastRow As Integer, Cnt As Integer, Cnt2 As Integer, Cnt3 As Integer
With Sheets("Sheet1")
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
'names (rows)
For Cnt = 4 To LastRow
'name/months (columns)
For Cnt2 = 2 To 4
If .Cells(Cnt, Cnt2) <> vbNullString Then
'months (columns
For Cnt3 = 6 To 17
If LCase(.Cells(Cnt, Cnt2)) = LCase(.Cells(3, Cnt3)) Then
.Cells(Cnt, Cnt3) = .Cells(3, Cnt2)
Exit For
End If
Next Cnt3
End If
Next Cnt2
Next Cnt
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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