VBA comment cells according to its value, based on conditions

excelquestion11

New Member
Joined
Aug 12, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi guys, this is my first time posting on the forum to seek for advises... I learned VBA all from google plus record macro
I am facing a problem which for every month, I have to update an excel based on another excel, and there r really a lot of rows thus consuming a lot of time on this task.

The task is like this:

Sheet1 (original excel) :

a
b​
c​
d​
e​
f​
1​
Products
Jan-22
Feb-22
Mar-22
Apr-22
May-22
2​
A1​
200​
400​
400​
100​
150​
3​
A2​
100​
100​
300​
300​
100​
4​
A3​
200​
200​
300​
300​
200​
5​
A4​
100​
100​
150​
100​
100​
6​
A5
0​
0​
0​
0​
0​
7​
A6
0​
0​
0​
0​
0​


Sheet 2 (updated information):

abcdefg
1YearSelling monthChannelSales typeStatusProductsExtra
QTY
22022JanA1 offConfirmedA1200
32022JanAexpandConfirmedA2400
42022FebB1 offConfirmedA3100
52022FebB1 monthCancelledA450
62022MarCSpecial eventConfirmedA5600
72022MarCSpecial eventConfirmedA6100
82022MarASpecial eventConfirmedA6200

What I will do is:
  • Start from Sheet 2 Row 1
  • Looking at column A, B, E, F, eg 2022 Jan, confirmed, A1
  • Go to sheet 1, getcell= column (Jan-22) and rows(A1), and found cell B2 (value 100)
  • Add comment in cell B2: A: 200 (values are from sheet2 Channel + Extra Qty, C2 & G2 in this case)
And then sheet2 row 2...row 3...looping...

Therefore, I am looking for VBA code online and searched for a long time ... what I got so far is base on VBA Macro to comment cells according to its value

Sub macro1()
Dim C1 As Range
Set CMwb=ActiveWorkbook.Sheets("Sheet1")
Set BBwb=ActiveWorkbook.Sheets("Sheet2")
BBLastRow=BBwb.Cells(BBwb.Rows.Count, "J").End(xlUp).Row
CMLastRow=CMwb.Cells(CMwb.Rows.Count,"P").End(xlUp).Row

With CreateObject("scripting.dictionary")
For Each C1 In BBwb.Range("F"& BBLastRow)
.Item(C1.Value) = C1.Offset(, 1).Value
Next C1
For Each C1 In CMwb.Range("A"& CMLastRow)
If Not C1.Offset(,
1).Comment Is Nothing Then C1.Offset(,1).Comment.Delete
If .Exists(C1.Value) Then
Cl.Offset(,
1).AddComment
Cl.Offset(,
1).Comment.Text .Item(C1.Value)
End If
Next Cl
End With
End Sub

Sub macro2()
(basically the same as macro 1, just changing the red highlight from 1 to 2)

Sub call macro()
Set target = Sheet2.Range("A2:A8")
Set target2 = Sheet2.range ("B2:B8")
If target.Value = "2022" AND target2.value = "Jan"
Call Macro1
End If
If target.Value = "2022" AND target2.value = "Feb" Then
Call Macro2
If target.Value = "2022" And target2.value = "Mar" Then
.
.
End If
End Sub


I think the above VBA can only add "Extra QTY" to the comment (actually even cant as I dunno y the comment only allows value, eg text, but not numbers) and also I think it cannot support me to call macro for each month as there will be too many macros in the Sub call macro().
I really hope someone could give me some advices on this issue, or will it be impossible to write a vba base on my task nature?

Thank you very much.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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