Avatar of Flora Edwards
Flora EdwardsFlag for Sweden

asked on 

how to fix this VBA code

i am trying to put this in array of cells but it overwrites other values

i want the objQuickFix headers to appear in Columns

like this Computer:   "Description: " "Hot Fix ID: "  as header of columns and then the data to put in rows.

i tried the below code but it overwrites the previous data and it is a mess.

 Sub Test()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set colQuickFixes = objWMIService.ExecQuery _
    ("Select * from Win32_QuickFixEngineering")
 
For Each objQuickFix In colQuickFixes
    Cells(1, 1).Value = "Computer: "
    Cells(2, 1).Value = objQuickFix.CSName
    Cells(1, 2).Value = "Description: "
    Cells(2, 2).Value = objQuickFix.Description
    Cells(2, 3).Value = "Hot Fix ID: "
    Cells(3, 3).Value = objQuickFix.HotFixID
    Cells(3, 4).Value = "Installation Date: "
    Cells(4, 4).Value = objQuickFix.InstallDate
    Cells(4, 5).Value = "Installed By: "
    Cells(5, 5).Value = objQuickFix.InstalledBy
Next
End Sub

Open in new window

VBA

Avatar of undefined
Last Comment
Flora Edwards
Avatar of Thierry van Mourik
Thierry van Mourik
Flag of Netherlands image

Because you are overwriting the same rows, over and over again.

add a variable to the rows part of the cell

for example cell(B,1)

then add a b=b+1 to in the for-next loop.

You might want to get the 'headers' out of the for-next loop
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Flora Edwards
Flora Edwards
Flag of Sweden image

ASKER

Thank you very much
VBA
VBA

Visual Basic for Applications (VBA) enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library, but it can normally only run code within a host application rather than as a standalone program. It can, however, be used to control one application from another via OLE Automation. VBA is built into most Microsoft Office applications.

17K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo