Solved

powershell shell/excel populating numbers

Posted on 2016-08-30
4
26 Views
Last Modified: 2016-09-20
I have some code below with excel that runs but need help editing to  populate certain info. For example this updates another column with information in sequential order This part "$DEPT+ ([math]::floor($i++/$NUMBER)+1)"

I would like to be able to hard code this as for example: "Miami" and let this increment from Miami001 to a certain number like Miami300. If its possible The last thing is if I want do is exclude certain numbers "which I know might be very hard" For example if I ran the script and it starts at Miami001 to Miami300 and want to prevent Miami29 or Miami57 would this be able to exclude. Please let me know if anyone can help, thanks

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$NUMBER = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter a number per batch?")

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$DIR = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter the following. The complete path, file and the extension which should be an CSV")

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$DEPT = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter a unique name of the batches")


$excel = New-Object -ComObject excel.application
$excel.visible=$true
$wb = $excel.WorkBooks.open("$DIR")
$ws = $wb.Worksheets.Item(1)
$row = $ws.Range("2:2")
$i = 0
while ($row.Cells.Item(1,1).value2)
{
  $row.Cells.Item(1,2).value2 = $DEPT+ ([math]::floor($i++/$NUMBER)+1)
  $row = $row.Offset(1,0)
}
$wb.Save()
$excel.Quit()
Remove-Variable excel, wb, ws, rowcode]

Open in new window

0
Comment
Question by:techdrive
  • 2
4 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 41777921
You should be able to format the numeric value with leading zeroes
0
 

Author Comment

by:techdrive
ID: 41778883
I do not understand what you are saying. Can you provide an example?
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points (awarded by participants)
ID: 41778898
Test this:
$row.Cells.Item(1,2).value2 = $DEPT+ ([math]::floor($i++/$NUMBER)+1).ToString("000")

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question