Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

powershell shell/excel populating numbers

Posted on 2016-08-30
4
Medium Priority
?
30 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 46

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 46

Accepted Solution

by:
aikimark earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

721 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