• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 57
  • Last Modified:

vba code to appear names beside the total

Hi,

I would like to ask for an help.

I am trying a code in vba to give the unit name(column B) beside the unit total(column A), where ever the total names are there in column A the unit name should appear beside in column B, the data is not constant it changes every time when i run it. At the start of unit the unit name is available but the end where the total of unit is there the unit name is required.

Could you please assist on this, i have attached the example file of this scenario.
0
rdy123 rdy
Asked:
rdy123 rdy
  • 2
  • 2
1 Solution
 
MacroShadowCommented:
It seems like the file didn't get attached...
1
 
rdy123 rdyAuthor Commented:
Sorry. PFA
Book1.xlsx
0
 
MacroShadowCommented:
Here you go:
Sub Demo()
    Dim rng As Range
    Dim cell As Range
    Dim strUnitName As String
    
    Set rng = Selection
    For Each cell In rng.Cells
        If (cell.Value & "" <> "") And (cell.Offset(, 1) & "" <> "") Then
            strUnitName = cell.Offset(, 1)
        ElseIf (cell.Value & "" <> "") And (cell.Offset(, 1) = "") Then
            cell.Offset(, 1) = strUnitName
        End If
    Next
End Sub

Open in new window

0
 
rdy123 rdyAuthor Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now