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

vba code to appear names beside the total


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.
rdy123 rdy
rdy123 rdy
  • 2
  • 2
1 Solution
It seems like the file didn't get attached...
rdy123 rdyAuthor Commented:
Sorry. PFA
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
End Sub

Open in new window

rdy123 rdyAuthor Commented:
thank you
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