# Change value in A2 from one value to another

**URL:** <https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070>\
**Category:** PowerShell Help\
**Created:** [November 29, 2021, 5:57pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070 "2021-11-29T17:57:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mburke0920](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mburke0920](https://forums.powershell.org/u/mburke0920)\
**Post date:** [November 29, 2021, 5:57pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/1 "2021-11-29T17:57:31Z")

</div>

Good Morning! I have a CSV file which has the value 2380 in cell A2. I need to change this to a different value so that my file will load to a supplementary system. I am attempting to do this with Powershell but nothing seems to work. Any advice is greatly appreciated!

Thanks!  
Melissa

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 29, 2021, 6:08pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/2 "2021-11-29T18:08:10Z")

</div>

Please share your code.

---

<div class="post-metadata">

**Author:** ![mburke0920](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mburke0920](https://forums.powershell.org/u/mburke0920)\
**Post date:** [November 29, 2021, 6:14pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/3 "2021-11-29T18:14:39Z")

</div>

I would, but I got discouraged and deleted it all. I had imported the CSV, made range a2 = 3680 (which is the new value) and then exported CSV, didnt get an error but value wasnt updated in the file.

I’ll try to redo the code and post again.

---

<div class="post-metadata">

**Author:** ![mburke0920](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mburke0920](https://forums.powershell.org/u/mburke0920)\
**Post date:** [December 15, 2021, 7:04pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/4 "2021-12-15T19:04:56Z")

</div>

Here is the code that I got to work, EXCEPT it changes the value of 2380 to 3680 in the WHOLE csv, not just the first row, or cell A2. The issue is, the file has a header, but it has a row above the header that tells the file where to load in my system. This row is required. the number I want to change is the company ID so the file knows where to put the data in the csv in my tables. How do I get this to code to change only the value 2380 to 3680 in the first row of the file or specifically cell A2.

```auto
[io.file]::readalltext(“D:\autoloader\Geosouthern_Production\Geosouthern_Production.csv”).replace(“2380”,”3680”) | Out-File D:autoloader\Geosouthern_Production\GeosouthernProd.csv -Encoding ascii –Force

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 15, 2021, 10:28pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/5 "2021-12-15T22:28:58Z")

</div>

If you have a valid CSV file you should treat it as such. It would have been nice if you shared a little more details and maybe some sample data to play with. Especially the first line of you source file. If it’s a certain format PowerShell may ignore it anyway.

I assumed that you CSV file uses a comma as the delimiter.

```auto
$Source = 'D:\autoloader\Geosouthern_Production\Geosouthern_Production.csv'
$Output = 'D:autoloader\Geosouthern_Production\GeosouthernProd.csv'

$Content = Get-Content -Path $Source
$NewCSV =
$Content | 
    Select-Object -Skip 1 |
        ConvertFrom-Csv -Delimiter ',' |
            ForEach-Object {
                $_.'company ID' = 3680
            } |
                Out-String
$Content[0],$NewCSV | Out-File -FilePath $Output

```

… untested … try with test data first!

---

<div class="post-metadata">

**Author:** ![mburke0920](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mburke0920](https://forums.powershell.org/u/mburke0920)\
**Post date:** [December 15, 2021, 11:34pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/6 "2021-12-15T23:34:22Z")

</div>

Thanks for the info Olaf! I’m not sure how to send you the sample CSV, so here is a screenshot. they highlighted cell is what I am trying to change. The code you provided, sadly doesn’t work.

Thanks, Melissa

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/e/eaea04965226559ceb6276f0b250e1d3dca11bcd.png)

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 15, 2021, 11:57pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/7 "2021-12-15T23:57:04Z")

</div>

> [@mburke0920](#):
>
> The code you provided, sadly doesn’t work.

… that description doesn’t help at all. Try to keep in mind - I cannot see your screen and I cannot read your mind. 😉

> [@mburke0920](#):
>
> so here is a screenshot.

That’s worst way of sharing sample data. How should I use it? 😉

> [@mburke0920](#):
>
> how to send you the sample CSV

You simply copy a few lines of the plain text content of the file and post it here **formatted as code**. This way we can copy and play with it. 😉

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [December 16, 2021, 12:50am UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/8 "2021-12-16T00:50:30Z")

</div>

Your CSV is a bit wonky in relation to header rows … This worked for me using this sample data:

```auto
COMPANY,2380,1
File1,Field2,Field3,Field4,Field5
1,2,3,4,5
6,7,8,9,0
1,2,3,4,5
6,7,8,9,0

```

```auto
[io.file]::readalltext('c:\temp\test.csv').Replace('2380','3680') | Out-File C:\temp\Test-Out.CSV -Encoding ASCII -Force

```

```auto
PS C:\Users\XXXXXX> type c:\temp\test-out.csv
COMPANY,3680,1
File1,Field2,Field3,Field4,Field5
1,2,3,4,5
6,7,8,9,0
1,2,3,4,5
6,7,8,9,0

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 16, 2021, 1:20am UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/9 "2021-12-16T01:20:13Z")

</div>

> [@tonyd](#):
>
> Your CSV is a bit wonky in relation to header rows

Amen. 😏 😜 😃

> [@tonyd](#):
>
> This worked for me using this sample data:

> [@tonyd](#):
>
> `).Replace('2380','3680')`

If you have a value of “2380” in any other cell of the csv you will mess it up. 😉

Assumed the CSV file ALWAYS has the values shown in the first row in the first row and is comma separated you could do it like this:

```auto
$Source = 'D:\autoloader\Geosouthern_Production\Geosouthern_Production.csv'
$Output = 'D:autoloader\Geosouthern_Production\GeosouthernProd.csv'

$Content = Get-Content -Path $Source
"COMPANY,3680,1", $Content[1..($Content.count)] | Out-File -FilePath $Output

```

---

<div class="post-metadata">

**Author:** ![mburke0920](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mburke0920](https://forums.powershell.org/u/mburke0920)\
**Post date:** [December 20, 2021, 3:46pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/10 "2021-12-20T15:46:59Z")

</div>

Exactly this! Thank you!! That worked awesomely! And thank you for the tips on how to share the information on here. I’m still new to the forum but truly appreciate your help!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:19pm UTC](https://forums.powershell.org/t/change-value-in-a2-from-one-value-to-another/18070/11 "2024-05-16T20:19:57Z")

</div>


