See attached sample file.
Column “A” & “B” will be added/changed manually.
Row 1 does not change
I need to copy value of “B” to corresponding column [D to I]which matches the value in same row as “A”.
Translated:
A2=”Q”, B2=$10, I need to fill D[“Q”]2 with $10
A3=”R”, B3=$20, I need to fill E[“R”]3 with $20
etc
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
copy value to corresponding cell/column
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » copy value to corresponding cell/column
- This topic has 15 replies, 3 voices, and was last updated 10 years, 4 months ago.
AuthorTopicWSskipro
AskWoody LoungerJanuary 20, 2015 at 5:29 pm #498240Viewing 10 reply threadsAuthorReplies-
Maudibe
AskWoody_MVPJanuary 20, 2015 at 7:21 pm #1485608skipro,
in cell D2 place the formula =IF($A2=D$1,$B2,””)
Copy across to I2 then copy all those cells down
HTH,
Maud -
zeddy
AskWoody_MVPJanuary 21, 2015 at 5:42 am #1485630Hi
Seems like you are processing receipts and amounts to their respective columns.
I would recommend using a dropdown for your entries in column [A], to make sure they are not ‘mistyped’. For example, if you had an entry in column [A] as “Hotell”, it will not be posted to any the [Hotel] column.
You can create a named list of valid entries and use this for the dropdown.zeddy
-
WSskipro
AskWoody LoungerJanuary 21, 2015 at 5:09 pm #1485715Maud,
Thanks. Easy enough [when you know what you are doing].
Since I cannot predict the number of row entries, and other formulas will probably be entered below this section, such as subtotals and other analysis modes [see attached file], can this be done without specifying the actual cells by embedding a formula in each as you suggested. I am thinking of a script that would work in the specific columns with undefined number of rows so the “added” formulas could just be moved down increasing the number of entries that could be entered in the future?
I will not be readily available to modify [add formulas to cells] as needed. -
Maudibe
AskWoody_MVPJanuary 21, 2015 at 6:35 pm #1485762Skipro,
Consider the following code. As long as you start on row 2 and you maintain a blank row between the last pair (in Col A and B) and the Subtotals row, you can add as many rows of data as you like. No formulas needed.
HTH,
MaudCode:Public Sub MatchColums() Dim AvailableRow As Long Dim col As Integer AvailableRow = Range(“A2”).End(xlDown).Row For I = 2 To AvailableRow col = WorksheetFunction.Match(Cells(I, 1), Range(“D1:I1”), 0) + 3 Cells(I, col) = Cells(I, 2) Next I End Sub
-
zeddy
AskWoody_MVPJanuary 22, 2015 at 4:05 am #1485803Hi Maud
..I would use an ‘onEntry’ trigger that, when an entry is made in column , it would match the corresponding column for the adjacent cell (in col [A] ) and directly ‘post’ the entered value to the correct column. No formulas would then be required (making the spreadsheet smaller and faster)
zeddy
-
zeddy
AskWoody_MVP
-
-
-
Maudibe
AskWoody_MVPJanuary 22, 2015 at 4:22 am #1485805 -
WSskipro
AskWoody LoungerJanuary 22, 2015 at 10:58 am #1485864Maud,
Again thank you.Using your last revised sample, if I change a value in “A”, it adds “B” in “D-I” appropriately, great. But it leaves the old value in “D-I”, not so great. I do not know if this was intended due to the idea that the entire column “A” was fixed. It is not and can vary [QQ,R,TTT,UU,VVV] while still using only those already stated options [Q,R,S,T,U,V]. Can “D-I” reflect the current “A,B”, that is only 1 entry per row?
Also, Q-V may change, easy fix, but the user may need to add choices, such as Q-Z. I can change macro as needed, but again I may not be available to do so. Can this be “written” in? -
zeddy
AskWoody_MVPJanuary 23, 2015 at 9:31 am #1486083Hi skipro
see attached file.
I modified Maud’s code to clear the data first, before running the code via the button [Run code]
see sheet named [maud] in attached file.On sheet named [zeddy] in attached file, I use the dropdown method (discussed in earlier post) together with event trapping to place values in the relevant column.
zeddy
-
-
WSskipro
AskWoody LoungerJanuary 23, 2015 at 4:46 pm #1486236 -
Maudibe
AskWoody_MVPJanuary 23, 2015 at 7:31 pm #1486264Skipro,
I Think I have resolved the issues while taking Zeddy’s 2 points into consideration.
The following code removes the button to run the code but instead runs when a change is made in columns A or B. It also performs validation on the changed value that you made.
One question: Suppose you entered a q instead of a Q, would you want the code to change it to uppercase and then match or would you rather have it case sensitive?
HTH,
MaudCode:Private Sub Worksheet_Change(ByVal Target As Range) [COLOR=”#008000″]’——————————- ‘DECLARE AND SET VARIABLES[/COLOR] Dim AvailableRow As Long, LastCol As Long Dim col As Integer LastCol = ActiveSheet.Cells(1, Application.Columns.Count).End(xlToLeft).Column If Intersect(Target, Range(“A2:B13″)) Is Nothing Then Exit Sub [COLOR=”#008000”]’——————————- ‘VALIDATE CHANGED VALUE IN COL A[/COLOR] If Not Intersect(Target, Range(“A2:A13”)) Is Nothing Then For I = 4 To LastCol If Target = Cells(1, I) Then GoTo Continue1 Next I MsgBox “You have entered ” & Chr(34) & Target & Chr(34) & ” which is not a value that matches a column header” Application.EnableEvents = False Target = “” Application.EnableEvents = True Target.Select Exit Sub End If Continue1: [COLOR=”#008000″]’——————————- ‘VALIDATE CHANGED VALUE IN COL B[/COLOR] If Not Intersect(Target, Range(“B2:B13”)) Is Nothing Then If WorksheetFunction.IsNumber(Target) Then GoTo Continue2 MsgBox “You have entered ” & Chr(34) & Target & Chr(34) & ” which a non numeric value in column B” Application.EnableEvents = False Target = “” Application.EnableEvents = True Target.Select Exit Sub End If Continue2: [COLOR=”#008000″]’——————————- ‘PLACE VALUE IN RIGHT COLUMN[/COLOR] Range(“D2:I13”).ClearContents AvailableRow = Range(“A2”).End(xlDown).Row For I = 2 To AvailableRow col = WorksheetFunction.Match(Cells(I, 1), Range(“D1:I1”), 0) + 3 Cells(I, col) = Cells(I, 2) Next I End Sub
-
WSskipro
AskWoody LoungerJanuary 23, 2015 at 8:20 pm #1486266Maud,
Thanks.
I would like it case insensitive.
Are you aware that if an invaild entry is placed in A your message appears and if oked, or if an entry in A is deleted, the cell goes blank. Then if a cell in B is also changed, all entries in D-I below the blank A also go blank. They reappear when a valid entry is placed in the blank cell. -
Maudibe
AskWoody_MVP -
zeddy
AskWoody_MVPJanuary 25, 2015 at 4:32 pm #1486503Hi Maud
..in an ideal world, I would have the range [D2:V13] protected (with or without a password).
Then, in your code, you could add the line to ‘unprotect’ this range prior to making changes, e.g. add
[D2:I13].unprotect
..prior to your
‘PLACE VALUE IN RIGHT COLUMN
Range(“D2:I13”).ClearContents..and then re-protect after changes are made.
The reason for doing this is that at present, a User can ‘manually’ re-type a numeric value
in the block [D2:I13] e.g. ‘post’ a value to a different column than that specified in corresponding column [A] (and even a different amount to that specified in column ). You can even have 2 (or more) values entered in the same row under different columns.
Of course, one answer to the User is ‘don’t do that’.
But see attached example to show what could happen.zeddy
-
-
Maudibe
AskWoody_MVPJanuary 25, 2015 at 4:36 pm #1486504Good point Zeddy!
Adding the line (in blue) should resolve that issue of allowing changes to be made directly in the grid.
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) [COLOR=”#0000FF”] If Not Intersect(Target, Range(“D2:I13”)) Is Nothing Then Range(“A1”).Select [/COLOR] Data = Target End Sub
Viewing 10 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
System Restore and Updates Paused
by
veteran
6 minutes ago -
Windows 10/11 clock app
by
Kathy Stevens
1 hour, 49 minutes ago -
Turn off right-click draw
by
Charles Billow
3 hours, 20 minutes ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
6 hours, 51 minutes ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
8 hours, 2 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
8 hours, 28 minutes ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
30 minutes ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
14 hours, 30 minutes ago -
KB5060842 Issue (Minor)
by
AC641
19 hours, 3 minutes ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
21 hours, 35 minutes ago -
24H2 may not be offered June updates
by
Susan Bradley
3 hours, 59 minutes ago -
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
1 day, 10 hours ago -
June 2025 updates are out
by
Susan Bradley
10 hours, 16 minutes ago -
Mozilla shutting Deep Fake Detector
by
Alex5723
2 days ago -
Windows-Maintenance-Tool (.bat)
by
Alex5723
1 day, 10 hours ago -
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
2 days, 3 hours ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
2 days, 3 hours ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
2 days, 3 hours ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
1 day, 19 hours ago -
re-install Windows Security
by
CWBillow
2 days, 6 hours ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
2 days, 10 hours ago -
macOS Tahoe 26
by
Alex5723
2 days, 4 hours ago -
Migrating from win10 to win11, instructions coming?
by
astro46
15 hours, 46 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
1 day, 19 hours ago -
Recommended watching : Mountainhead movie
by
Alex5723
1 day, 19 hours ago -
End of support for Windows 10
by
Old enough to know better
1 minute ago -
What goes on inside an LLM
by
Michael Covington
1 day, 14 hours ago -
The risk of remote access
by
Susan Bradley
9 hours, 43 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
46 minutes ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
2 days ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.