Please help - how do i insert a value to from a cell to another using macro.

monmon

Board Regular
Joined
Apr 1, 2013
Messages
84
Hi,

Please help me. I've the following data in Column E.

is it possible to use a macro such that once the macro detects that it is a blank cell, it will automatically combine the adjacent Column C cell combined with Column H cell to give a value?

Here is my data.

ABCDEFGH
tigermary LNLN
monkeyUS
dogtom GBGB

<TBODY>
</TBODY>



Here is my desired results. Note that cell E3 has become monkey US.

Please note that i would have a different list daily with varying amount of data.

Thanks for your help!

ABCDEFGH
1tigermary LNLN
2monkeymonkey USUS
3dogtom GBGB

<TBODY>
</TBODY>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe:

Code:
Sub monmon()
Dim lr As Long
Dim rcell As Range

lr = Cells(Rows.Count, 3).End(xlUp).Row

For Each rcell In Range("E2:E" & lr)

    If rcell.Value = "" Then rcell.Value = rcell.Offset(, -2).Value & " " & rcell.Offset(, 3).Value
    
Next rcell

End Sub
 
Upvote 0
Not tested but something like this may work

Sub combine1()
Dim Rng As Range
Set Rng = Range(Range("E1"), Range("E" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks)
Rng.Value = Rng.Offset(, -2).Value & " " & Rng.Offset(, 3)

End Sub
 
Upvote 0
Hi all, thanks for your help.

Here's another question.

If some cells in Column H is blank. is it possible to just include data cell in C?

What I meant is in the event cell H2 is missing (for example), how can i revise the code to make it contain cell C2 value?

In addition, if Cell C is missing, can i use cell D2 combined with H2 instead?
 
Last edited:
Upvote 0
Hi all, thanks for your help.

Here's another question.

If some cells in Column H is blank. is it possible to just include data cell in C?

What I meant is in the event cell H2 is missing (for example), how can i revise the code to make it contain cell C2 value?

In addition, if Cell C is missing, can i use cell D2 combined with H2 instead?

Anyone?
 
Upvote 0
Not sure I follow you, so test on a copy first, to see if this does what you want.

Code:
Sub monmon()
Dim lr As Long
Dim rcell As Range

lr = Cells(Rows.Count, 3).End(xlUp).Row

For Each rcell In Range("E2:E" & lr)

    If rcell.Offset(, -2).Value <> "" Then
        If rcell.Value = "" Then rcell.Value = rcell.Offset(, -2).Value & " " & rcell.Offset(, 3).Value
    ElseIf rcell.Offset(, -2).Value = "" Then
        If rcell.Value = "" Then rcell.Value = rcell.Offset(, -1).Value & " " & rcell.Offset(, 3).Value
    End If
    
Next rcell

End Sub
 
Upvote 0
Not sure I follow you, so test on a copy first, to see if this does what you want.

Code:
Sub monmon()
Dim lr As Long
Dim rcell As Range

lr = Cells(Rows.Count, 3).End(xlUp).Row

For Each rcell In Range("E2:E" & lr)

    If rcell.Offset(, -2).Value <> "" Then
        If rcell.Value = "" Then rcell.Value = rcell.Offset(, -2).Value & " " & rcell.Offset(, 3).Value
    ElseIf rcell.Offset(, -2).Value = "" Then
        If rcell.Value = "" Then rcell.Value = rcell.Offset(, -1).Value & " " & rcell.Offset(, 3).Value
    End If
    
Next rcell

End Sub

Hi John, that's great! Thanks for help!
 
Upvote 0

Forum statistics

Threads
1,203,462
Messages
6,055,562
Members
444,799
Latest member
CraigCrowhurst

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